const util = require("./utils/util.js");
App({
  onLaunch() {
    // 加载Anton字体
    util.loadFont()

    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })


    const sysInfo = wx.getWindowInfo();
    this.globalData.statusBarHeight = sysInfo.statusBarHeight

    // 获取胶囊按钮位置
    const { top, height } = wx.getMenuButtonBoundingClientRect();
    this.globalData.capsulePaddingStatusBarHeight = top - sysInfo.statusBarHeight
    this.globalData.capsuleHeight = height

    // 获取自定义顶部标题栏高度
    this.globalData.navBarHeight = sysInfo.statusBarHeight + height + 2 * (top - sysInfo.statusBarHeight) - 1

    // 获取屏幕高度
    this.globalData.screenHeight = sysInfo.screenHeight
    this.globalData.screenWidth = sysInfo.screenWidth

    // 获取底部安全距离
    this.globalData.bottomSafeAreaHeight = sysInfo.screenHeight - sysInfo.safeArea.bottom

    // 计算底部导航高度
    this.globalData.tabbarHeight = sysInfo.screenHeight - sysInfo.safeArea.bottom + 50
  },

  globalData: {
    userInfo: null,
    statusBarHeight: 0,  // 手机状态栏高度
    navBarHeight: 0,  // 程序标题栏高度
    capsulePaddingStatusBarHeight: 0, // 胶囊按钮距离状态栏的高度
    capsuleHeight: 0, // 胶囊按钮的高度
    screenHeight: 0,
    screenWidth: 0,
    bottomSafeAreaHeight: 0,
    tabbarHeight: 0,
  }
})